package com.gzucm.Scholarship.config;

import com.gzucm.Scholarship.common.base.BaseEntity;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.UUIDGenerator;

import java.io.Serializable;

/**
 * @Author: yanhang_chen
 * @Date: 2020-11-06 13:02:04
 */
public class CustomUUIDGenerator extends UUIDGenerator {
    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        Object id = ((BaseEntity) object).getId();
        if (id != null) {
            return (Serializable) id;
        }
        return super.generate(session, object);
    }
}

